#ifndef __PROTOCOL_H
#define __PROTOCOL_H

#ifdef __cplusplus
 extern "C" {
#endif

#include "System.h"

#include "Serial.h"

#define	FRAME_MAX_LEN	250
#define	FRAME_MAX_NUM	3


typedef enum {
	ProtocolOK				= 0,
	ProtocolFAIL			= 1,
	ProtocolErrVerify		= 2,
	ProtocolErrNoData		= 3,
    ProtocolErrType	    	= 4,
    ProtocolErrResp     	= 5,
    ProtocolErrSendCall 	= 6,
	ProtocolErrRrotocolCall	= 7,
}ProtocolSta_E;


typedef struct{
	UINT8	data[FRAME_MAX_LEN];
	UINT8	fun;
	UINT8   sequen;
	UINT8	cmdID;
	UINT8	len;
	union{
		UINT16  value;
		UINT8	buf[2];
	}crc;
}FrameData_T,*pFrameData_T;

typedef struct{
    UINT8 (*parse)(FifoBuf_T *_buf , FrameData_T *_frame);
	UINT8 (*configFrame)(FrameData_T *_frame,uint8_t *_data,UINT8 *_len);
	UINT8 (*respondFrame)(FrameData_T *_frame,uint8_t *_data,UINT8 *_len);
	UINT8 (*idleFrame)(FrameData_T *,uint8_t *_data,UINT8 *_len);
}ProtocolFunc_T;


typedef UINT32 (*sendCall_t) (UINT8,UINT8 *,UINT32);
typedef UINT32 (*parseCall_t) (UINT8,FrameData_T *);

extern 	FrameData_T	    g_frameSend;
extern 	FrameData_T	    g_frameRece;
extern	UINT8 			g_ucCmdBuf[FRAME_MAX_LEN];


void	Protocol_Init(void);
UINT8 	Protocol_Process(void);
void	Protocol_SendCallRegister(sendCall_t _callBackFunc);
void 	Protocol_ParseCallRegister(parseCall_t _callBackFunc);

UINT8 	Protocol_ConfigFrame(UINT8 _type,FrameData_T *_frame,UINT8 *_data,UINT8 *_len);
UINT8 	Protocol_SendRespFrame(UINT8 _type,FrameData_T *_frame,UINT8 _port);
UINT8 	Protocol_SendFrame(UINT8 _type,FrameData_T *_frame,UINT8 _port,UINT8 _flags);

void 	Protocol_ErrorReport(SysError_E _errorCode,UINT8 *_param,UINT8 _len);
	




#endif

#ifdef __cplusplus
 }
#endif
